<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="js/jquery-3.2.1.min.js"></script>
    <style type="text/css">
        .autoCode {
            width: 100px;
            height: 30px;
            border: 1px solid gray;
        }
    </style>
    <script type="text/javascript">
            var seed = new Array(
                'abcdefghijklmnopqrstuvwxyz',
                'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                '0123456789'
            )//创建需要的数据数组
            var idx,i;
            var result = '';
            for(i = 0;i < 4;i ++) {
                idx = Math.floor(Math.random()*3);//随机获取一个3以内的整数
                result += seed[idx].substr(Math.floor(Math.random()*(seed[idx].length)),1); //从seed[idx]中随机选中一个数据并接在result后面
            }
            $(".autoCode").text(result);
            function test() {
                var inputdata = document.getElementById("v_code").value.toLowerCase();//toLowerCase()将字符串转换成小写
                var autodata = document.getElementById("autoCode").innerHTML.toLowerCase();
                if(inputdata == autodata) {
                    alert("验证通过！");
                }
                else {
                    alert("验证码输入错误！");
                }
            }
    </script>
</head>
<body>
<span>验证码</span><input type="text" id="v_code">
<!--<label id="autoCode" value="">-->
<!--<input type="button" value="点击获取验证码" onClick="autoCode.innerHTML=createCode(4)">-->
<!--</label>-->
<span class="autoCode" id="autoCode"></span>
<input type="submit" value="登陆" onClick="test()">
<!--<script type="text/javascript">-->
<!--window.onload()=autoCode.innerHTML=createCode(4);-->
<!--</script>-->
</body>
</html>